package app.runner;

import java.util.Timer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import app.htby.utils.IOTSUtils;
import app.monitor.MonitorTimer;

@Component
public class ApplicationRunner implements CommandLineRunner {

	/** 系统ip */
	@Value("${server.ip}")
	public String THIS_SYSTEM_IP;
	/** 系统port */
	@Value("${server.port}")
	public String THIS_SYSTEM_PORT;

	private static Logger logger = LoggerFactory.getLogger(ApplicationRunner.class);

	public void run(String... var1) throws Exception {
		logger.info("This will be execute when the project was started!");
		//设置系统id
		IOTSUtils.iotsSystemMonitor.setSystemId(IOTSUtils.THIS_SYSTEM_ID);
		//设置当前系统 IP + port
		IOTSUtils.iotsSystemMonitor.setSystemIp(THIS_SYSTEM_IP + ":" + THIS_SYSTEM_PORT);

		Timer timer = new Timer();
		// 10秒后开始执行，每分钟执行一次，可进行配置
		timer.schedule(new MonitorTimer(), IOTSUtils.MONITOR_TIMER_DELAY_TIME, IOTSUtils.MONITOR_TIMER_INTERVAL_TIME);
	}
}
